﻿using Karbel;
using System;
using System.Data;
using System.IO;
namespace ConfExpert.Portable
{
    public class DataAccess
    {
        static DataManager dm = null;

        static DataAccess()
        {
            string gate = "";
            string databaseNamePostFix = "";

            FileInfo fi = new FileInfo("c:\\ce\\ceSayimKontrol.dat");
            string[] lines = File.ReadAllLines(fi.FullName);

            foreach (string line in lines)
            {
                if (line.Contains("DatabaseNamePostFix"))
                    databaseNamePostFix = line.Replace("DatabaseNamePostFix", "").Replace("\t", "").Trim();
                else if (line.Contains("Gate"))
                    gate = line.Replace("Gate", "").Replace("\t", "").Trim();
            }

            string server = "10.0.0.4";
            //server = "confexpert.karbel.com";
            ConfExpert.SayimKontrol.GateService.ConfExpertGateSoapClient gateClient = new SayimKontrol.GateService.ConfExpertGateSoapClient();
            gateClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(string.Format("http://{0}/ceGate/ceGate.asmx", server));

            DataSet dsCredentials = gateClient.GetCredentials(gate, gate, server, databaseNamePostFix);
            //DataSet dsCredentials = gateClient.GetCredentials(gate, gate, "confexpert.karbel.com", "Test");
            string connectionString = dsCredentials.Tables["ConnectionString"].Rows[0]["ConnectionString"].ToString();

            dm = new  DataManager(connectionString);
        }

        public static System.Data.DataSet GetSayimKontrol()
        {
             
            return dm.ExecuteDataSet("Sayim_GetKontrolList");
        }

        public static DataSet GetRollDetail(int RollId)
        {
           
            return dm.ExecuteDataSet("Sayim_GetRollDetail", RollId);
        }

        public static void UpdateSayimSonuc(int RollId, int SonucId)
        {
           
            dm.ExecuteNonQuery("Sayim_UpdSayimKontrolSonuc",RollId,SonucId);
        }

        public static void InsBuffer(string RollId)
        {
             
            dm.ExecuteNonQuery("InsBuffer",null, RollId, 'K');
        }
    }
}
